package com.alibaba.cloudalibabaserver.controller;


import com.alibaba.cloudalibabaserver.bean.Order;
import com.alibaba.cloudalibabaserver.bean.OrderItem;
import com.alibaba.cloudalibabaserver.service.OrderService;
import lombok.AllArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/api/orders")
@AllArgsConstructor
@Slf4j
public class OrderController {


    private final OrderService orderService;

//    @PostMapping
//    public OrderItem createOrder(@RequestParam Long userId,
//                                 @RequestParam Double amount) {
//        return orderService.createOrder(userId, amount);
//    }

    @PostMapping("/batch/{count}")
    public String batchCreateOrders(@PathVariable int count) {
        orderService.batchCreateOrders(count);
        return "成功创建 " + count + " 个订单";
    }

    @GetMapping("/user/{userId}")
    public List<Order> getOrdersByUser(@PathVariable Long userId) {
        return orderService.getOrdersByUserId(userId);
    }

    @GetMapping("/{orderId}")
    public Order getOrder(@PathVariable Long orderId) {
        return orderService.getOrderById(orderId);
    }

    @GetMapping
    public List<Order> getAllOrders() {
        return orderService.getAllOrders();
    }

    @GetMapping("/range")
    public List<Order> getOrdersByRange(@RequestParam Long startUserId,
                                        @RequestParam Long endUserId) {
        return orderService.getOrdersByUserIdRange(startUserId, endUserId);
    }
}
